/**
 * Euler's Totient function (phi)
 * 
 * @author Jon Ludwig
 */

import java.math.*;
import java.util.*;

public class EulerTotient {

	public static BigInteger phi(BigInteger n)
	{
		BigInteger res = BigInteger.ONE;
		
		ArrayList<Factor.ExpNumber> factors = Factor.factor(n);
		
		for (Factor.ExpNumber r : factors)
		{
			res = res.multiply(
					r.base.pow(r.exponent.intValue()-1).multiply(
							r.base.subtract(BigInteger.ONE)));
		}
		
		return res;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length < 1) {
			System.out.println("usage: java EulerTotient a");
			return;
		}
		
		BigInteger a = new BigInteger(args[0]);
		
		BigInteger res = phi(a);
		System.out.println(res);
	}

}
